﻿/*jslint sloppy: true, devel: true, white: true*/
/*global $, $$, ko, toggleMenuViewModel */

/*
 *  Page load
 */
$(function () {
    $('[title]:not(.tip-right)').tooltip({
        placement:'auto'
    });
    $('.tip-right').tooltip({
        placement: 'right'
    });
});

/*
 *  Change css class of the selected menu
 */
function focusMenu($menuItem) {
    $('.selected', $menuItem.parents('ul:first')).removeClass('selected');
    $menuItem.addClass('selected');
}

/*
 *  Detect user resize view
 */
function detectScreenResolution() {
    // detect screen resolution
    $(window).on('resize.layout', function () {
        clearTimeout(window.gResizeLayoutTimer);
        window.gResizeLayoutTimer = setTimeout('_resizeView();', window.gEffectDuration);
    });
    
    _resizeView();
}

/*
 *  Execute some functions when user resize view
 */
function _resizeView() {
    var mainContainerWidth = $('.container:first').width(),
        $settingBox;
    if (mainContainerWidth !== window.gCurrentContainerWidth) {
        window.gCurrentContainerWidth = mainContainerWidth;

        //Global action
        $settingBox = $('#setting-box');
        if ($settingBox[0]) {
            $settingBox.position({
                of: $('#btn-setting'),
                my: 'right top',
                at: 'right+40 bottom',
                collision: 'fit fit'
            });
        }
        /****************************/
        
        switch (mainContainerWidth) {
            case 1140:
                //Case : Large devices (large desktops, 1200px and up)
                break;
                
            case 940:
                //Case : Medium devices (desktops, 992px and up)
                break;
                
            case 720:
                //Case : Small devices (tablets, 768px and up)
                break;
            
            default:
                //Case : Extra small devices (phones, less than 768px)
                break;
        }
    }
}